package com.ideaaedi.zoo.example.springboot.seata_sharding.alpha.config;

import com.ideaaedi.commonspring.transaction.DefaultManualTransactionSupport;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.annotation.PostConstruct;
import java.util.Objects;

/**
 * 指定手动本地事务 使用的数据源管理器
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2022/3/25 10:33
 */
@Slf4j
@Configuration
public class ManualTransactionConfig {
    
    @Resource
    private DataSourceTransactionManager defaultTransactionManager;
    
    @PostConstruct
    public void initTransactionManager() {
        // 本地事务手动管理器
        DefaultManualTransactionSupport.initTransactionManager(Objects.requireNonNull(defaultTransactionManager));
    }
}
